﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace AppShare.Web.Controls
{
    public class WikiContent : HtmlGenericControl
    {
        public WikiContent() : base() { }
        public WikiContent(string tag) : base(tag) { }

        [Bindable(true, BindingDirection.TwoWay)]
        [DefaultValue(null)]
        public object DataContext { get; set; }

        protected override void OnPreRender(EventArgs e)
        {
            base.TagName = "p";
            var content = DataContext as string;

            if (content != null)
            {
                if (content.StartsWith("~") || content.StartsWith("http"))
                {
                    base.Controls.Add(new HtmlImage
                    {
                        Src = content,
                    });
                }
                else
                {
                    base.Controls.Add(new HtmlGenericControl
                    {
                        TagName = "span",
                        InnerHtml = content,
                    });
                }
            }

            base.OnPreRender(e);
        }
    }
}